package cn.hrlly.tao2shou.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.hrlly.tao2shou.R;
import cn.hrlly.tao2shou.domain.Orders;
import cn.hrlly.tao2shou.utils.ImageUtil;

/**
 * User: gengliang
 * Date: 2016-02-15
 * Time: 15:27
 */

public class BuyerCompleteOrderAdapter extends BaseAdapter {

    private ArrayList<Orders> list;
    private ImageLoader imageLoader;
    private LayoutInflater layoutInflater;

    public BuyerCompleteOrderAdapter(ArrayList<Orders> list, Context context) {
        this.list = list;
        imageLoader = ImageLoader.getInstance();
        layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.layout_buyer_complete_order, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final Orders order = list.get(position);
        if (order != null) {
            imageLoader.displayImage(order.getCommodityPhoto(), holder.ivCommodityPhoto, ImageUtil.getOptions());
            holder.tvCommodityName.setText(order.getCommodityName());
            holder.tvSellerNickname.setText(order.getNickname());
        }
        return convertView;
    }
    static class ViewHolder {
        @Bind(R.id.ivCommodityPhoto)
        ImageView ivCommodityPhoto;
        @Bind(R.id.tvSellerNickname)
        TextView tvSellerNickname;
        @Bind(R.id.tvCommodityName)
        TextView tvCommodityName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
